import React, { PureComponent } from 'react';
import { connect } from 'dva';
import "./form.less"
import "../../Common.less"
import { Form, Input } from 'antd';
const { TextArea } = Input;
class crossSectionDetail extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            propTypeList: [],
            partList: [],
            visibleList: [],
            effictiveList: [],
            plist: [],
            pileShow: false,
            partShow: false,
        }
        this.onConfirm = this.onConfirm.bind(this)
        this.onSelect2 = this.onSelect2.bind(this)
    }
    onConfirm(params = {}) {
        
        return new Promise((resolve, reject) => {
            this.props.form.validateFields(async (error, values) => {
                
                values.constraints = {}
                let { required, precision, min, max, regExp } = values
                Object.assign(values.constraints, { required, precision, min, max, regExp })
                if (JSON.stringify(values.constraints) == "{}") {
                    values.constraints = null
                }
                if (!error) {
                    await this.setState({
                        confirmData: values,
                        confirmType: 2
                    })
                    if (params.onSuccess) {
                        params.onSuccess(values);
                    }
                    resolve()
                } else {

                    if (params.onError) {
                        params.onError(error);
                    }
                    reject()
                }

            })
        })

    }

    onSelect2(a, b) {
        this.props.form.setFieldsValue({
            name: b.props.children
        })
    }
    async componentDidMount() {
        if (this.props.onLoaded) {
            this.props.onLoaded(this);
        }
        let { dictlist, extra } = this.props;
        const { colNum } = this.props.extra;
        let arr = []
        if (colNum - 0 > 0) {
            for (let i = 0; i < colNum; i++) {
                arr.push({
                    id: i + 1,
                    name: i + 1
                })
            }
        } else {
            arr.push({
                id: 0,
                name: '无'
            })
        }
        this.setState({
            plist: arr,
            isShowList: dictlist.filter(item => item.dictType == "is_show"),
            isEffectiveList: dictlist.filter(item => item.dictType == "is_effective"),
            isRequiredList: dictlist.filter(item => item.dictType == "is_required"),
            propertyTypeList: dictlist.filter(item => item.dictType == "property_type"),
            unitlist: dictlist.filter(item => item.dictType == "unit"),
            blockList: dictlist.filter(item => item.dictType == "dynamic_block"),
        })

    }
    render() {
        const { form, extra } = this.props;
        const { getFieldDecorator } = form;
        const {} = this.state
        return (
            <Form
                style={{ marginTop: "20px" }}
                labelAlign="right"
                labelCol={{ span: 6 }}
                wrapperCol={{ span: 18 }}
            >
                <Form.Item className="half" label='名称'>
                    {getFieldDecorator('name', {
                        rules: [
                            { required: true, message: '截面库' }
                        ],
                        initialValue: extra.mode == 'edit' && extra.propData ? extra.propData.name : null
                    })(
                        <Input disabled={extra.mode == 'edit'} placeholder="请输入截面库名称" />
                    )}
                </Form.Item>
                <Form.Item disabled={extra.mode == 'edit'} className="half" label='分类'>
                    {getFieldDecorator('name', {
                        rules: [
                            { required: true, message: '分类' }
                        ],
                        initialValue: extra.mode == 'edit' && extra.propData ? extra.propData.name : null
                    })(
                        <Input placeholder="请输入分类" />
                    )}
                </Form.Item>
               
                <Form.Item disabled={extra.mode == 'edit'} className="half" label='状态'>
                    {getFieldDecorator('name', {
                        rules: [
                            { required: true, message: '状态' }
                        ],
                        initialValue: extra.mode == 'edit' && extra.propData ? extra.propData.name : null
                    })(
                        <Input placeholder="请输入状态" />
                    )}
                </Form.Item>
                <Form.Item className="half" label='备注'>
                    {getFieldDecorator('remark', {
                        rules: [
                            { required: false, message: '备注' }
                        ],
                    })(
                        <Input placeholder="备注"></Input>
                    )}
                </Form.Item>
                <Form.Item disabled={extra.mode == 'edit'} className="half" label='描述'>
                    {getFieldDecorator('name', {
                        rules: [
                            { required: true, message: '描述' }
                        ],
                        initialValue: extra.mode == 'edit' && extra.propData ? extra.propData.name : null
                    })(
                        <TextArea rows={4}  placeholder="请输入描述"/>
                    )}
                </Form.Item>
                <div className="half">

                </div>
            </Form>
        )
    }
}
export default connect(
    ({ dict: { dictlist } }) => ({
        dictlist
    }),
    dispatch => ({

    })
)(Form.create('crossSectionDetail', {

})(crossSectionDetail));